use model_graph_types::channel::pubsub::Topic;

use crate::transport::{exist_connection, prepare_follower};

pub async fn subscribe(topic_obj: Topic) -> anyhow::Result<()> {
    let topic = &topic_obj.topic;
    let peer_id = &topic_obj.peer_id;

    //查询是否有点对点连接
    if !exist_connection(peer_id)? {
        //
        if let Err(err) = prepare_follower(peer_id).await {
            tracing::error!("{}建立数据通道请求失败!{}", peer_id, err);
            //   Err(anyhow::anyhow!("数据通道建立失败{}", err));
        }
    }
    //
    super::subscribe_topic(topic_obj)?;

    Ok(())
}
